const jQuery = window.jQuery;
//对象比较
export const compareParams = (a, b) => {
  let aProps = Object.getOwnPropertyNames(a);
  let bProps = Object.getOwnPropertyNames(b);
  let flag = true;
  if( aProps.length !== bProps.length ) return false;
  for (let i in a) {
    if(a[i] !== b[i]) {
      if(typeof(a[i] === 'object')) {
        if( !compareParams(a[i], b[i])) {
          flag = false;
          break;
        }
      } else {
        flag = false;
        break;
      }
    }
  }
  return flag
}
export const communicatePreViewImg = (_this) => {
  window.preViewImg(jQuery(_this), 'isFormCommunicate');
}



export const getRemarkHtml = (log_remarkHtml = '') => {
  let remarkHtmlTemp = log_remarkHtml;
  remarkHtmlTemp = remarkHtmlTemp.replace(/<img/g, `<img onClick='window.communicatePreViewImg(this)' class= 'communicateImgPlay' `);

  let reg = /href=\"\/spa\/document\/index.jsp\?.*?\"/g;
    let docs = log_remarkHtml.match(reg);
    docs && docs.map((item) => {
        if (/\&(amp;){0,1}id=(\d*?)\&/g.test(item)) {
            let docid = RegExp.$2;
            remarkHtmlTemp = remarkHtmlTemp.replace(item, `onclick="window.showFormDoc(${docid},{})"`);
        }
    })
    let reg2 = /href=\"\/workflow\/request\/ViewRequestForwardSPA.jsp.*?\"/g;
    let reqs = log_remarkHtml.match(reg2);
    reqs && reqs.map((v) => {
        if (/\&(amp;){0,1}requestid=(\d*?)\&/g.test(v)) {
            let requestid = RegExp.$2;
            remarkHtmlTemp = remarkHtmlTemp.replace(v, `onclick="window.showFormReq(${requestid},{})"`);
        }
    })

    //跳转人力资源卡片
    let reg3 = /href=\"\/hrm\/HrmTab.jsp\?.*?\"/g;
    let ats = log_remarkHtml.match(reg3);
    ats && ats.map((v) => {
        if (/\&(amp;){0,1}id=(\d*?)\"/g.test(v)) {
            let id = RegExp.$2;
            remarkHtmlTemp = remarkHtmlTemp.replace(v, `onclick="window.showHoverWindow('/spa/hrm/static4mobile/index.html#/resourceInfo/${id}','/req')"`);
        }
    })

    //附件上传字段  <a\s+href="(.*)"\s+title="(.*)"\s*>(.*)<\s*/a>
    let reg5 =  /href=\"javascript[:]void[(]0[)]\;\"\s+onclick=\"(parent.openFullWindowHaveBar)[(]\'\/spa\/document\/index.jsp\?.*?[)]\"/g;
    let files = remarkHtmlTemp.match(reg5);
    files && files.map((item) => {
        if (/\&(amp;){0,1}id=(\d*?)\&/g.test(item)) {
            let docid = RegExp.$2;
            remarkHtmlTemp = remarkHtmlTemp.replace(item, `onclick="window.showFormDoc(${docid},{},'/req')"`);
        }
    })

    //超链接
    let reg6 = /href=(\"([^<>"\']*)\"|\'([^<>"\']*)\')/gi;
    let a_links = remarkHtmlTemp.match(reg6);
    a_links&&a_links.map(item=>{
        if(/\"([^<>"\']*)\"|\'([^<>"\']*)\'/g.test(item)){
            let url = RegExp.$1;
            remarkHtmlTemp = remarkHtmlTemp.replace(item, `onclick="window.showHoverWindow('${url}','/req')"`);
        }
    })

    //表单内签字意见中的附件、文档
    let reg7 = /onclick=\"addDocReadTag[(][0-9]*[)]\;openFullWindowHaveBar[(](\'\/spa\/document\/index.jsp\?.*?\')[)]\"/g;
    let remark_docs = remarkHtmlTemp.match(reg7);
    remark_docs && remark_docs.map(item=>{
        if (/id=(\d*?)\&/g.test(item)) {
            let docid = RegExp.$1;
            remarkHtmlTemp = remarkHtmlTemp.replace(item, `onclick="window.showFormDoc(${docid},{})"`);
        }
    })
    //表单内签字意见中的流程
    let reg8 = /onclick=\"openFullWindowHaveBar[(](\'\/workflow\/request\/ViewRequestForwardSPA.jsp.*?\')[)]\"/g;
    let remark_reqs = remarkHtmlTemp.match(reg8);
    remark_reqs && remark_reqs.map((v) => {
        if (/requestid=(\d*?)\&/g.test(v)) {
            let requestid = RegExp.$1;
            remarkHtmlTemp = remarkHtmlTemp.replace(v, `onclick="window.showFormReq(${requestid},{})"`);
        }
    })

  return remarkHtmlTemp;
}
window.communicatePreViewImg = communicatePreViewImg;